package com.lanhe.pay.controller;

import com.lanhe.common.constant.Constants;
import com.lanhe.common.core.controller.BaseController;
import com.lanhe.common.core.domain.AjaxResult;
import com.lanhe.common.core.page.TableDataInfo;
import com.lanhe.order.domain.LhOrdersWithdrawal;
import com.lanhe.order.service.ILhOrdersWithdrawalService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 用户提现控制器
 *
 * @author zhanggl
 * @since 2024年01月05日21:40:18
 */
@RestController
@RequestMapping("/api/withdrawal")
public class WithdrawalController extends BaseController {

	/**
	 * 服务对象
	 */
	@Resource
	private ILhOrdersWithdrawalService lhOrdersWithdrawalService;

	/**
	 * 分页查询所有数据
	 */
	@GetMapping("/list")
	public TableDataInfo list(LhOrdersWithdrawal lhOrdersWithdrawal) {
		startPage();
		lhOrdersWithdrawal.setMemberId(getUserId());
		List<LhOrdersWithdrawal> lists = lhOrdersWithdrawalService.selectOrdersWithdrawalList(lhOrdersWithdrawal);
		for (LhOrdersWithdrawal list : lists) {
			list.setAuditStatusName(Constants.OrdersWithdrawalStatus.getOrdersWithdrawalStatusName(list.getAuditStatus()));
			list.setPayedName(Constants.OrdersPayedStatus.getOrdersPayedStatusName(list.getPayed()));
		}
		return getDataTable(lists);
	}

	/**
	 * 提现申请
	 *
	 * @author zhanggl
	 * @date 2024年01月05日22:43:10
	 */
	@PostMapping("/add")
	public AjaxResult add(@RequestBody LhOrdersWithdrawal ordersWithdrawal) {
		ordersWithdrawal.setMemberId(getUserId());
		return toAjax(lhOrdersWithdrawalService.insertOrdersWithdrawal(ordersWithdrawal));
	}
}

